package de.mhu.mandalaui.text;

import de.mhu.mandalaui.Response;
import de.mhu.mandalaui.attributes.ArrayAttribute;

public class DropdownField extends Field {

	private ArrayAttribute options = new ArrayAttribute();
	private String optionsValue = "id";
	private String optionsText = "name";
	
	protected void doInitialize() {
		options.setOwner(this);
	}
	
	@Override
	public void render(Response response) {
		//<select data-bind="
		//  options: prefixList, 
		//  optionsValue: 'id', 
		//  optionsText: 'name', 
		//  value: f_prefix, 
		//  visible: isEditDetails"></select>
		
		response.registerAttribute(options);
		response.startTag("select", "form-control", this,
				"disabled", isEnabled() ? null : "disabled",
				"data-bind","options: " + options.getBindCall() + ", optionsValue: " + optionsValue + ", optionsText: " + optionsText );
		response.endTag("select");
	}

	public ArrayAttribute getOptions() {
		return options;
	}

	public void setOptions(ArrayAttribute options) {
		this.options = options;
		if (options != null) options.setOwner(this);
	}

	public String getOptionsValue() {
		return optionsValue;
	}

	public void setOptionsValue(String optionsValue) {
		this.optionsValue = optionsValue;
	}

	public String getOptionsText() {
		return optionsText;
	}

	public void setOptionsText(String optionsText) {
		this.optionsText = optionsText;
	}
	
}
